package com.jason.kotlin.gank.ui.adapter

import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ctetin.expandabletextviewlibrary.ExpandableTextView
import com.jason.kotlin.gank.R
import com.jason.kotlin.gank.model.RollHistoryBean

/**
 * @description: RollHistoryTodayAdapter
 *
 * @author ChenBaoyang
 * @date 4/24/21 11:15
 */
class RollHistoryTodayAdapter : BaseQuickAdapter<RollHistoryBean, BaseViewHolder>(R.layout.roll_item_history_today) {


    override fun convert(holder: BaseViewHolder, item: RollHistoryBean) {
        item.run {
            holder.setText(R.id.tv_title, title)
            holder.setText(R.id.tv_time, "${year}-${month}-${day}")
            val expandView = holder.getView<ExpandableTextView>(R.id.expand_text_view)
            expandView.setContent(details)
            val showIv = holder.getView<ImageView>(R.id.iv_show)
            if (TextUtils.isEmpty(picUrl)) {
                showIv.visibility = View.GONE
            } else {
                showIv.visibility = View.VISIBLE
                val options = RequestOptions().apply {
                    fitCenter()
                    placeholder(R.drawable.pic_gray_bg)
                }
                Glide.with(context)
                    .load(picUrl)
                    .apply(options)
                    .into(showIv)
            }
        }
    }
}